package com.yzk.train.business.controller.admin;

import com.yzk.train.business.request.TrainQueryReq;
import com.yzk.train.business.request.TrainSaveReq;
import com.yzk.train.business.response.TrainQueryResp;
import com.yzk.train.business.service.TrainSeatService;
import com.yzk.train.business.service.TrainService;
import com.yzk.train.common.response.PageResp;
import com.yzk.train.common.response.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/train")
public class TrainAdminController {

    @Resource
    private TrainService trainService;

    @Resource
    private TrainSeatService trainSeatService;

    @PostMapping("/save")
    public Result<Object> save(@Valid @RequestBody TrainSaveReq req) {
        String message = trainService.save(req);
        return Result.ok(message);
    }

    @GetMapping("/list")
    public Result<PageResp<TrainQueryResp>> queryList(@Valid TrainQueryReq req) {
        PageResp<TrainQueryResp> pageResp = trainService.queryList(req);
        return Result.ok(pageResp);
    }

    @GetMapping("/all")
    public Result<List<TrainQueryResp>> queryAll() {
        List<TrainQueryResp> list = trainService.queryAll();
        return Result.ok(list);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> delete(@PathVariable Long id) {
        trainService.delete(id);
        return Result.ok("删除成功");
    }

    @GetMapping("/gen-seat/{code}")
    public Result<Object> genSeat(@PathVariable String code) {
        trainSeatService.genTrainSeat(code);
        return Result.ok("生成座位成功");
    }

}
